package net.pimpas.web.jsf.renderers.accordionpanel.ajax;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import net.pimpas.web.jsf.components.accordionpanel.UIAccordionPanel;
import net.pimpas.web.jsf.components.ajax.context.ResponseWriterAjaxWrapper;
import net.pimpas.web.jsf.renderers.AjaxRendererBase;
import net.pimpas.web.jsf.renderers.html.ajax.AjaxHtmlRenderer;

import org.dom4j.Node;

public class AjaxAccordionPanelRenderer extends AjaxHtmlRenderer implements AjaxRendererBase {

	@Override
	public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
		
		// change id
		ResponseWriterAjaxWrapper wrapper = (ResponseWriterAjaxWrapper) context.getResponseWriter();
		Node element = wrapper.getElement();
		Node id = element.selectSingleNode("id");
		id.setText((String) component.getAttributes().get(UIAccordionPanel.CONTENT_ID));
		
		super.encodeEnd(context, component);
	}
}